// @formatter:off
/**
* @file bundlepreview.js
* @author Alejandro Dario Simi
* @date $Date: 2013-05-27 04:56:35 +0000 (Mon, 27 May 2013) $
*
* $Id: bundlepreview.js 67 2013-05-27 04:56:35Z daemonraco@gmail.com $
* $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/themes/default/templates/generics/bundlepreview.js $
*/
// @formatter:on

var CURRENT_ID = false;
var PREVIOUS_ID = false;
var PREVIEWS = new Array();
var MULTI_PREVIEWS = new Array();
var TIMER_ON = false;

function animatePreview(pos) {
	if(CURRENT_ID != PREVIOUS_ID && PREVIOUS_ID != false) {
		$(PREVIOUS_ID + "_img").attr("src", PREVIEWS[PREVIOUS_ID]);
	}

	if(TIMER_ON == false) {
		TIMER_ON = true;
		if(CURRENT_ID != false && MULTI_PREVIEWS[CURRENT_ID].length > 0) {
			PREVIOUS_ID = CURRENT_ID;

			if(pos > (MULTI_PREVIEWS[CURRENT_ID].length - 1)) {
				pos = 0;
			}

			$(CURRENT_ID + "_img").attr("src", MULTI_PREVIEWS[CURRENT_ID][pos]);
			pos++;
			setTimeout("TIMER_ON = false;animatePreview(" + pos + ");", 500);
		} else {
			TIMER_ON = false;
		}
	}
}

function animatePreviewsOf(id) {
	CURRENT_ID = "#" + id;
	animatePreview(1);
}

function retorePreviewsOf(id) {
	CURRENT_ID = false;
}

$(function() {
	$("a.animated-bundle-preview").bind({
		mouseenter: function() {
			animatePreviewsOf($(this).attr("id"));
		},
		mouseleave: function() {
			retorePreviewsOf($(this).attr("id"));
		}
	});
});
